package com.example.user_management_p1.config;
import com.example.user_management_p1.interceptor.AdministratorsInterceptor;
import com.example.user_management_p1.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class LoginInterceptorConfig implements WebMvcConfigurer {
    @Autowired
    RedisTemplate redisTemplate;
    private static final List<String> list1=new ArrayList<>();
    private static final List<String> list2=new ArrayList<>();
     static {
        list1.add("/user/updateps");
        list2.add("/user/updatetp");
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        HandlerInterceptor interceptor1=new LoginInterceptor(redisTemplate);
        HandlerInterceptor interceptor2=new AdministratorsInterceptor(redisTemplate);
        registry.addInterceptor(interceptor1).addPathPatterns(list1);
        registry.addInterceptor(interceptor2).addPathPatterns(list2);
    }
}
